package com.liaoban.app.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.liaoban.app.R;
import com.liaoban.app.adapter.BlackListAdapter;
import com.liaoban.app.api.type.Black;
import com.liaoban.app.api.type.request.WuserinfoRequest;
import com.liaoban.app.biz.CommonBiz;
import com.liaoban.app.constants.Constant;
import com.liaoban.app.helper.ToastHelper;
import com.liaoban.app.ui.base.BaseListActivity;
import com.liaoban.app.ui.rank.SearchActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ybc on 2018/7/30 0030.
 * 黑名单
 */
public class BlackListActivity extends BaseListActivity<Black> {
    @BindView(R.id.iv_right)
    ImageView ivRight;

    @Override
    public String getNewTitle() {
        return getString(R.string.black_list);
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return new BlackListAdapter(null);
    }

    @Override
    public void itemChildClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {
        Black black = (Black) baseQuickAdapter.getData().get(position);
        switch (view.getId()) {
            case R.id.iv_del:
                showRunningDialog(R.string.committing);
                WuserinfoRequest wuserinfoRequest = new WuserinfoRequest();
                wuserinfoRequest.setWuserId(black.getWuserId() + "");
                startTask(CommonBiz.getInstance().wuserBlack(wuserinfoRequest), baseResponse -> {
                    ToastHelper.show(this, baseResponse.msg);
                    if (1 == baseResponse.code) {
                        baseQuickAdapter.remove(position);
                    }
                });
                break;
        }
    }

    @Override
    public void itemClick(BaseQuickAdapter baseQuickAdapter, View view, int position) {

    }

    @Override
    public void getData() {
        startTask(CommonBiz.getInstance().blackList(), listBaseResponse -> {
            doSuc(listBaseResponse.data, listBaseResponse.totalPageCount);
        });
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        ivRight.setImageResource(R.mipmap.ic_search_title);
        ivRight.setVisibility(View.VISIBLE);
    }

    @OnClick(R.id.iv_right)
    public void right() {
        startActivity(new Intent(this, SearchActivity.class));
    }
}
